package com.powernode.controller;

import com.powernode.common.Result;
import com.powernode.domain.StatBean;
import com.powernode.dto.StatDto;
import com.powernode.service.VisitLogService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("stat")
public class StatController {
    @Resource
    private VisitLogService visitLogService;

    @RequestMapping("statVisitLogCount.do")
    public Result statVisitLogCount(StatDto statDto){
        try {
            List<StatBean> list = visitLogService.queryVisitLogCount(statDto);
            List<String> names = new ArrayList<>();
            List<Integer> values = new ArrayList<>();
            for (StatBean statBean : list) {
                names.add(statBean.getName());
                values.add(statBean.getValue());
            }
            Map<String, Object> map = new HashMap<>();
            map.put("name", names);
            map.put("value", values);
            return new Result(200,"查询成功",0L,map);
        }catch (Exception e){
            e.printStackTrace();
            return Result.OPT_ERROR;
        }
    }
}
